/********************************************************
 Name          : AntelCfgOID.c
 Author        : Khachatur Gyozalyan
 Copyright     : Copyright by Antel Systems
 Description   :
 **********************************************************/
// Include Files
#include "AntelCfgOID.h"
#include "stdio.h"
#include "string.h"
#include <malloc.h>
#include "file_system.h"
#include "at25dfx.h"
#include "cmx7164_api.h"

struct CfgFile * CfgFiles;
void cfg_init(void)
{
	int i,N,M;
	struct file_t file;

	CfgFiles = (struct CfgFile *)malloc(sizeof(struct CfgFile) * 3/* 3 File */);

	// User Defined ObjectID
	CfgFiles[0].Nodes = (struct Node *)malloc(4 * sizeof(struct Node));

	CfgFiles[0].Nodes[0].Objects = (struct Object *)malloc(32 * sizeof(struct Object));// 1.X.X (Channel Table)

	for(i = 0 ; i < 32 ; i++)
	{
		CfgFiles[0].Nodes[0].Objects[i].size = (int *)malloc(3 * sizeof(int));         // 1.i.X
		CfgFiles[0].Nodes[0].Objects[i].size[0] = SIZEOF_FREQUENCY_CARRIER_NUMBER;     // 1.i.1
		CfgFiles[0].Nodes[0].Objects[i].size[1] = SIZEOF_OUTPUT_POWER;                 // 1.i.2
		CfgFiles[0].Nodes[0].Objects[i].size[2] = SIZEOF_SYMBOL_RATE;	               // 1.i.3
		CfgFiles[0].Nodes[0].Objects[i].Object_size = SIZEOF_CANNEL;
	}
	CfgFiles[0].Nodes[0].Node_size = SIZEOF_CANNEL_TABLE;

	CfgFiles[0].Nodes[1].Objects = (struct Object *)malloc(3 * sizeof(struct Object)); // 2.X.X (Operation Settings)

	CfgFiles[0].Nodes[1].Objects[0].size = (int *)malloc(3 * sizeof(int));             // 2.1.X (User Identification)
	CfgFiles[0].Nodes[1].Objects[0].size[0] = SIZEOF_USER_NAME;                        // 2.1.1
	CfgFiles[0].Nodes[1].Objects[0].size[1] = SIZEOF_UNIT_NAME;                        // 2.1.2
	CfgFiles[0].Nodes[1].Objects[0].size[2] = SIZEOF_LOCATION;                         // 2.1.3
	CfgFiles[0].Nodes[1].Objects[0].Object_size = SIZEOF_DEVICE_INDIVIDUALIZATION;

	CfgFiles[0].Nodes[1].Objects[1].size = (int *)malloc(7 * sizeof(int));             // 2.2.X (User Interface)
	CfgFiles[0].Nodes[1].Objects[1].size[0] = SIZEOF_PRIMARY_INTERFACE_SELECT;         // 2.2.1
	CfgFiles[0].Nodes[1].Objects[1].size[1] = SIZEOF_INTERFACE_TIMEOUT;		           // 2.2.2
	CfgFiles[0].Nodes[1].Objects[1].size[2] = SIZEOF_ASYNCHRONOUS_BAUDRATE;            // 2.2.3
	CfgFiles[0].Nodes[1].Objects[1].size[3] = SIZEOF_ASYNCHRONOUS_DATABITS;            // 2.2.4
	CfgFiles[0].Nodes[1].Objects[1].size[4] = SIZEOF_ASYNCHRONOUS_PARITY;              // 2.2.5
	CfgFiles[0].Nodes[1].Objects[1].size[5] = SIZEOF_ASYNCHRONOUS_STOPBITS;            // 2.2.6
	CfgFiles[0].Nodes[1].Objects[1].size[6] = SIZEOF_ASYNCHRONOUS_FLOWCONTROL;         // 2.2.7
	CfgFiles[0].Nodes[1].Objects[1].Object_size = SIZEOF_ASYNCHRONOUS;

	CfgFiles[0].Nodes[1].Objects[2].size = (int *)malloc(3 * sizeof(int));             // 2.3.X (Sleep Mode)
	CfgFiles[0].Nodes[1].Objects[2].size[0] = SIZEOF_SLEEP_MODE_REG;                   // 2.3.1
	CfgFiles[0].Nodes[1].Objects[2].size[1] = SIZEOF_QUIET_TIMEOUT;                    // 2.3.2
	CfgFiles[0].Nodes[1].Objects[2].size[2] = SIZEOF_WAKEUP_TIMEOUT;                   // 2.3.3
	CfgFiles[0].Nodes[1].Objects[2].Object_size = SIZEOF_SLEEP_MODE;

	CfgFiles[0].Nodes[1].Node_size = SIZEOF_OPERATION_SETTINGS;

	CfgFiles[0].Nodes[2].Objects = (struct Object *)malloc(1 * sizeof(struct Object)); // 3.X.X (Wireless Link)

	CfgFiles[0].Nodes[2].Objects[0].size = (int *)malloc(7 * sizeof(int));             // 3.1.X (UHF)
	CfgFiles[0].Nodes[2].Objects[0].size[0] = SIZEOF_CANNEL_NUMBER;                    // 3.1.1
	CfgFiles[0].Nodes[2].Objects[0].size[1] = SIZEOF_OUTPUT_POWER_LEVEL;               // 3.1.2
	CfgFiles[0].Nodes[2].Objects[0].size[2] = SIZEOF_MODULATION_TYPE;                  // 3.1.3
	CfgFiles[0].Nodes[2].Objects[0].size[3] = SIZEOF_FEC_TYPE;			               // 3.1.4
	CfgFiles[0].Nodes[2].Objects[0].size[4] = SIZEOF_SCRAM;								// 3.1.5
	CfgFiles[0].Nodes[2].Objects[0].size[5] = SIZEOF_CARRIER_FREQ_NUMBER;				// 3.1.6
	CfgFiles[0].Nodes[2].Objects[0].size[6] = SIZEOF_FREQ_NUMBER_SYMBOLRATE;			// 3.1.7

	CfgFiles[0].Nodes[2].Node_size = CfgFiles[0].Nodes[2].Objects[0].Object_size = SIZEOF_UHF;

	CfgFiles[0].Nodes[3].Objects = (struct Object *)malloc(4 * sizeof(struct Object)); // 4.X.X (Network Settings)

	CfgFiles[0].Nodes[3].Objects[0].size = (int *)malloc(3 * sizeof(int));             // 4.1.X (Network Protocol Settings)
	CfgFiles[0].Nodes[3].Objects[0].size[0] = SIZEOF_BRIDGING_PROTOCOL;                // 4.1.1
	CfgFiles[0].Nodes[3].Objects[0].size[1] = SIZEOF_SNMP_PROTOCOL;                    // 4.1.2
	CfgFiles[0].Nodes[3].Objects[0].size[2] = SIZEOF_SNMP_TRAP_TIMEOUT;                // 4.1.3
	CfgFiles[0].Nodes[3].Objects[0].Object_size = SIZEOF_NETWORK_PROTOCOL_SETTINGS;

	CfgFiles[0].Nodes[3].Objects[1].size = (int *)malloc(3 * sizeof(int));             // 4.2.X (Wi-Fi Settings)
	CfgFiles[0].Nodes[3].Objects[1].size[0] = SIZEOF_NETWORK_REGISTER;		           // 4.2.1
	CfgFiles[0].Nodes[3].Objects[1].size[1] = SIZEOF_ACCESS_POINT_NAME;		           // 4.2.2
	CfgFiles[0].Nodes[3].Objects[1].size[2] = SIZEOF_SSID;				               // 4.2.3
	CfgFiles[0].Nodes[3].Objects[1].Object_size = SIZEOF_WIFI_SETTINGS;

	CfgFiles[0].Nodes[3].Objects[2].size = (int *)malloc(5 * sizeof(int));             // 4.3.X (TCP/IP Settings)
	CfgFiles[0].Nodes[3].Objects[2].size[0] = SIZEOF_TCPIP_REGISTER;                   // 4.3.1
	CfgFiles[0].Nodes[3].Objects[2].size[1] = SIZEOF_IP_ADDRESS;	                   // 4.3.2
	CfgFiles[0].Nodes[3].Objects[2].size[2] = SIZEOF_SUBNET_MASK;	                   // 4.3.3
	CfgFiles[0].Nodes[3].Objects[2].size[3] = SIZEOF_DEFAULT_GATEWAY;                  // 4.3.4
	CfgFiles[0].Nodes[3].Objects[2].size[4] = SIZEOF_DNS_SERVER;	                   // 4.3.5
	CfgFiles[0].Nodes[3].Objects[2].Object_size = SIZEOF_TCPIP_SETTINGS;

	CfgFiles[0].Nodes[3].Objects[3].size = (int *)malloc(3 * sizeof(int));             // 4.4.X (Network Security)
	CfgFiles[0].Nodes[3].Objects[3].size[0] = SIZEOF_SECURITY_TYPE;                    // 4.4.1
	CfgFiles[0].Nodes[3].Objects[3].size[1] = SIZEOF_ENCRYPTION_TYPE;                  // 4.4.2
	CfgFiles[0].Nodes[3].Objects[3].size[2] = SIZEOF_SECURITY_KEY;                     // 4.4.3
	CfgFiles[0].Nodes[3].Objects[3].Object_size = SIZEOF_NETWORK_SECURITY;

	CfgFiles[0].Nodes[3].Node_size = SIZEOF_NETWORK_SETTINGS;

	find_file(&file, "UCFG");
	CfgFiles[0].sector_number = file.sector_number;
	// End of User Defined ObjectID
	//------------------------------------------------------------------------------------------------------------------------
	// Factry Configuration ObjectID
	CfgFiles[1].Nodes = (struct Node *)malloc(sizeof(struct Node));

	CfgFiles[1].Nodes[0].Objects = (struct Object *)malloc(2 * sizeof(struct Object)); // 1.X.X (Identification)
	CfgFiles[1].Nodes[0].Objects[0].size = (int *)malloc(9 * sizeof(int));		       // 1.1.X (Software Identification)
	CfgFiles[1].Nodes[0].Objects[0].size[0] = SIZEOF_MODEL;				               // 1.1.1
	CfgFiles[1].Nodes[0].Objects[0].size[1] = SIZEOF_DESCRIPTION;                      // 1.1.2
	CfgFiles[1].Nodes[0].Objects[0].size[2] = SIZEOF_PCBA_VERSION;       	           // 1.1.3
	CfgFiles[1].Nodes[0].Objects[0].size[3] = SIZEOF_SOFTWARE_VERSION;                 // 1.1.4
	CfgFiles[1].Nodes[0].Objects[0].size[4] = SIZEOF_GMSK_IMAGE_VERSION;               // 1.1.5
	CfgFiles[1].Nodes[0].Objects[0].size[5] = SIZEOF_FSK_IMAGE_VERSION;     	       // 1.1.6
	CfgFiles[1].Nodes[0].Objects[0].size[6] = SIZEOF_QAM_IMAGE_VERSION;                // 1.1.7
	CfgFiles[1].Nodes[0].Objects[0].size[7] = SIZEOF_ZIGBEE_IMAGE_VERSION;             // 1.1.8
	CfgFiles[1].Nodes[0].Objects[0].size[8] = SIZEOF_IDENT_RESERVED;            	   // 1.1.9
	CfgFiles[1].Nodes[0].Objects[0].Object_size = SIZEOF_SOFTWARE_IDENTIFICATION;

	CfgFiles[1].Nodes[0].Objects[1].size = (int *)malloc(3 * sizeof(int));		       // 1.2.X (System Identification)
	CfgFiles[1].Nodes[0].Objects[1].size[0] = SIZEOF_SERIAL_NUMBER_MAC;	               // 1.2.1
	CfgFiles[1].Nodes[0].Objects[1].size[1] = SIZEOF_MANUFACTORING_SERIAL_NUMBER;      // 1.2.2
	CfgFiles[1].Nodes[0].Objects[1].size[2] = SIZEOF_SECRET_KEY;					   // 1.2.3
	CfgFiles[1].Nodes[0].Objects[1].Object_size = SIZEOF_SOFTWARE_IDENTIFICATION;

	CfgFiles[1].Nodes[0].Node_size = SIZEOF_IDENTIFICATION;

	find_file(&file, "FCFG");
	CfgFiles[1].sector_number = file.sector_number;
	// End of Factry Configuration ObjectID
	//------------------------------------------------------------------------------------------------------------------------
	// Calibration Table ObjectID
	////CfgFiles[2].Nodes = (struct Node *)malloc((MAX_FREQ_SUB_BAND_N * 2 + 1) * sizeof(struct Node));
////
	////CfgFiles[2].Nodes[0].Objects = (struct Object *)malloc(1 * sizeof(struct Object));	// 1.X.X (General Purpose Calibration Parameters)
	////CfgFiles[2].Nodes[0].Objects[0].size = (int *)malloc(6 * sizeof(int));				// 1.1.X (General Purpose Calibration Parameters)
	////CfgFiles[2].Nodes[0].Objects[0].size[0] = SIZEOF_MAX_OUTPUT_POWER;					// 1.1.1
	////CfgFiles[2].Nodes[0].Objects[0].size[1] = SIZEOF_MIN_OUTPUT_POWER;					// 1.1.2
	////CfgFiles[2].Nodes[0].Objects[0].size[2] = SIZEOF_NUMBER_OF_FREQUENCY_SUB_BANDS;		// 1.1.3
	////CfgFiles[2].Nodes[0].Objects[0].size[3] = SIZEOF_NUMBER_OF_OUTPUT_POWER_LEVELS;		// 1.1.4
	////CfgFiles[2].Nodes[0].Objects[0].size[4] = SIZEOF_STOP_FREQBAND;						// 1.1.5
	////CfgFiles[2].Nodes[0].Objects[0].size[5] = SIZEOF_FREQERR;							// 1.1.6
	//////CfgFiles[2].Nodes[0].Objects[0].size[5] = SIZEOF_FREQ;							// 1.1.6
	//////CfgFiles[2].Nodes[0].Objects[0].size[6] = SIZEOF_IQ_ATTENUATOR;					// 1.1.7
	////CfgFiles[2].Nodes[0].Objects[0].Object_size = SIZEOF_FUNCTIONAL;
////
	////CfgFiles[2].Nodes[0].Node_size = SIZEOF_GENERAL_PURPOSE_CALIBRATION;
////
	////for(N = 0 ; N < MAX_FREQ_SUB_BAND_N ; N++)
	////{
		////CfgFiles[2].Nodes[2 * N + 1].Objects = (struct Object *)malloc(MAX_OUTPUT_POWER_LEVELS_M * sizeof(struct Object)); // 2*(N-1)+2.x.x (Transmitter Calibration Parameters for frequency band N)
		////for(M = 0 ; M < MAX_OUTPUT_POWER_LEVELS_M ; M++)
		////{
			////CfgFiles[2].Nodes[2 * N + 1].Objects[M].size = (int *)malloc(6 * sizeof(int));              // 2*(N-1)+2.1.x
			////CfgFiles[2].Nodes[2 * N + 1].Objects[M].size[0] = SIZEOF_OUTPUT_POWER_V;       // 2*(N-1)+1.M.1
			////CfgFiles[2].Nodes[2 * N + 1].Objects[M].size[1] = SIZEOF_FWD_ATTENUATOR;       // 2*(N-1)+1.M.2
			////CfgFiles[2].Nodes[2 * N + 1].Objects[M].size[2] = SIZEOF_FEEDBACK_ATTENUATOR;  // 2*(N-1)+1.M.3
			//////CfgFiles[2].Nodes[2 * N + 1].Objects[M].size[3] = SIZEOF_TSSI;               // 2*(N-1)+1.M.4
			////CfgFiles[2].Nodes[2 * N + 1].Objects[M].size[3] = SIZEOF_PHASE_SHIFT;          // 2*(N-1)+1.M.4
			////CfgFiles[2].Nodes[2 * N + 1].Objects[M].size[4] = SIZEOF_VAPC;          	   // 2*(N-1)+1.M.5
			////CfgFiles[2].Nodes[2 * N + 1].Objects[M].size[5] = SIZEOF_BASEBAND_ATTENUATOR;  // 2*(N-1)+1.M.6
////
			////CfgFiles[2].Nodes[2 * N + 1].Objects[M].Object_size = SIZEOF_OUTPUT_POWER_LEVEL_M;
////
		////}
////
		////CfgFiles[2].Nodes[2 * N + 1].Node_size = SIZEOF_TRANSMITTER_CALIBRATION_PARAMETERS;
////
		////CfgFiles[2].Nodes[2 + 2 * N].Objects = (struct Object *)malloc(1 * sizeof(struct Object)); // 2*(N-1)+2.x.x (Receiver Calibration Parameters for frequency band N)
		////CfgFiles[2].Nodes[2 + 2 * N].Objects[0].size = (int *)malloc(5 * sizeof(int));             // 2*(N-1)+2.1.x (Coefficientes)
		/////*CfgFiles[2].Nodes[2 + 2 * N].Objects[0].size[0] = SIZEOF_K_COEFFICIENT_OF_RSSI;           // 2*(N-1)+2.1.1
		////CfgFiles[2].Nodes[2 + 2 * N].Objects[0].size[1] = SIZEOF_B_COEFFICIENT_OF_RSSI;           // 2*(N-1)+2.1.2
		////CfgFiles[2].Nodes[2 + 2 * N].Objects[0].size[2] = SIZEOF_HIGH_GAIN_SWITCHING_RSSI_LEVEL;  // 2*(N-1)+2.1.3
		////CfgFiles[2].Nodes[2 + 2 * N].Objects[0].size[3] = SIZEOF_LOW_GAIN_SWITCHING_RSSI_LEVEL;   // 2*(N-1)+2.1.4
		////CfgFiles[2].Nodes[2 + 2 * N].Objects[0].size[4] = SIZEOF_I_DC_OFFSET_FOR_HIGH_GAIN;       // 2*(N-1)+2.1.5
		////CfgFiles[2].Nodes[2 + 2 * N].Objects[0].size[5] = SIZEOF_Q_DC_OFFSET_FOR_HIGH_GAIN;       // 2*(N-1)+2.1.6
		////CfgFiles[2].Nodes[2 + 2 * N].Objects[0].size[6] = SIZEOF_I_DC_OFFSET_FOR_LOW_GAIN;        // 2*(N-1)+2.1.7
		////CfgFiles[2].Nodes[2 + 2 * N].Objects[0].size[7] = SIZEOF_Q_DC_OFFSET_FOR_LOW_GAIN;        // 2*(N-1)+2.1.8*/
		////CfgFiles[2].Nodes[2 + 2 * N].Objects[0].size[0] = SIZEOF_SUB_BAND_START_FREQ;				// 2*(N-1)+2.1.1
		////CfgFiles[2].Nodes[2 + 2 * N].Objects[0].size[1] = SIZEOF_RECEIVER_SYSTEM_GAIN;				// 2*(N-1)+2.1.2
		////CfgFiles[2].Nodes[2 + 2 * N].Objects[0].size[2] = SIZEOF_AGC_TABLE;							// 2*(N-1)+2.1.3
		////CfgFiles[2].Nodes[2 + 2 * N].Objects[0].size[3] = SIZEOF_CHANNEL_EQUALIZATION_TABLE;		// 2*(N-1)+2.1.4
		////CfgFiles[2].Nodes[2 + 2 * N].Objects[0].size[4] = SIZEOF_BASEBAND_AMPLIFIER_TABLE;			// 2*(N-1)+2.1.5
		////CfgFiles[2].Nodes[2 + 2 * N].Objects[0].Object_size = SIZEOF_RSSI;
////
		////CfgFiles[2].Nodes[2 + 2 * N].Node_size = SIZEOF_RSSI;
	////}

	find_file(&file, "CBTB");
	CfgFiles[2].sector_number = file.sector_number;

	// End of Calibration Table ObjectID
	//------------------------------------------------------------------------------------------------------------------------
}

unsigned char gBoot_option;

struct CfgFile * get_cfg_file(int file_index)
{
	return &CfgFiles[file_index];
}

int get_cfg_address(struct CfgFile * Cfg,int id_0,int id_1,int id_2)
{
	int i,result = 0;
	id_0 -= 1;
	id_1 -= 1;
	id_2 -= 1;
	for(i = 0 ; i < id_0 ; i++)
		result += Cfg->Nodes[i].Node_size;
	for(i = 0 ; i < id_1 ; i++)
		result += Cfg->Nodes[id_0].Objects[i].Object_size;
	for(i = 0 ; i < id_2 ; i++)
		result += Cfg->Nodes[id_0].Objects[id_1].size[i];
	return result;
}

int get_cfg_size(struct CfgFile * Cfg,int id_0,int id_1,int id_2)
{
	int result;
	id_0 -= 1;
	id_1 -= 1;
	id_2 -= 1;
	result = Cfg->Nodes[id_0].Objects[id_1].size[id_2];
	return result;
}

void get_cfg(struct CfgFile * Cfg,void * data,int id_0,int id_1,int id_2)
{
	int size = get_cfg_size(Cfg,id_0,id_1,id_2);
	int address = get_cfg_address(Cfg, id_0,id_1,id_2) + SIZEOF_FILEHEADER + (Cfg->sector_number * AT25DFX_SECTOR_SIZE);

	at25dfx_read_bytes(address,size,data);
}

void get_cbtb(struct CfgFile * Cfg, void * data, int size, int address)
{
	address = address + SIZEOF_FILEHEADER + (Cfg->sector_number * AT25DFX_SECTOR_SIZE);

	at25dfx_read_bytes(address,size,data);
}

int get_object_address(struct CfgFile * Cfg,int id_0,int id_1)
{
	int i,result = 0;
	id_0 -= 1;
	id_1 -= 1;
	for(i = 0 ; i < id_0 ; i++)
		result += Cfg->Nodes[i].Node_size;
	for(i = 0 ; i < id_1 ; i++)
		result += Cfg->Nodes[id_0].Objects[i].Object_size;
	return result;
}

int get_object_size(struct CfgFile * Cfg,int id_0,int id_1)
{
	int result;
	id_0 -= 1;
	id_1 -= 1;
	result = Cfg->Nodes[id_0].Objects[id_1].Object_size;
	return result;
}


void get_object(struct CfgFile * Cfg,void * data,int id_0,int id_1)
{
	int size = get_object_size(Cfg,id_0,id_1);
	int address = get_object_address(Cfg,id_0,id_1) + SIZEOF_FILEHEADER + (Cfg->sector_number * AT25DFX_SECTOR_SIZE);

	at25dfx_read_bytes(address,size,data);
}

int get_node_address(struct CfgFile * Cfg,int id_0)
{
	int i,result = 0;
	id_0 -= 1;
	for(i = 0 ; i < id_0 ; i++)
		result += Cfg->Nodes[i].Node_size;
	return result;
}

int get_node_size(struct CfgFile * Cfg,int id_0)
{
	int result;
	id_0 -= 1;
	result = Cfg->Nodes[id_0].Node_size;
	return result;
}


void get_node(struct CfgFile * Cfg,void * data,int id_0)
{
	unsigned int size = get_node_size(Cfg,id_0);
	unsigned int address = get_node_address(Cfg,id_0) + (Cfg->sector_number * AT25DFX_SECTOR_SIZE);
	at25dfx_read_bytes(address,size,data);
}

void get_user_cfg_cfg(void * data,int id_0,int id_1,int id_2)
{
	if(id_0 > 100)
		id_0 = 1 ;
	if(id_1 > 100)
		id_1 = 1 ;
	if(id_2 > 100)
		id_2 = 1 ;
	//unsigned char *buffer;
	unsigned int size = get_cfg_size(&CfgFiles[USER_DEF_CONFIG_FILE],id_0,id_1,id_2);
	unsigned int address = get_cfg_address(&CfgFiles[USER_DEF_CONFIG_FILE],id_0,id_1,id_2);
	/*if(gBoot_option)
		address += SIZEOF_IDENTIFICATION;
	buffer = (unsigned char *)(INTERNAL_USER_CFG_FILE_ADDRESS + SIZEOF_FILEHEADER + address);
	memcpy(data,buffer,size);*/
	if(gBoot_option)
	{
		address += CfgFiles[FACTORY_CONFIG_FILE].sector_number * AT25DFX_SECTOR_SIZE;
		address += SIZEOF_IDENTIFICATION;
		address += SIZEOF_FILEHEADER;
	}
	else
	{
		address += CfgFiles[USER_DEF_CONFIG_FILE].sector_number * AT25DFX_SECTOR_SIZE;
		address += SIZEOF_FILEHEADER;
	}
	at25dfx_read_bytes(address,size,data);
}

void get_user_cfg_object(void * data,int id_0,int id_1)
{
	if(id_0 > 100)
		id_0 = 1 ;
	if(id_1 > 100)
		id_1 = 1 ;
	//unsigned char *buffer;
	unsigned int size = get_object_size(&CfgFiles[USER_DEF_CONFIG_FILE],id_0,id_1);
	unsigned int address = get_object_address(&CfgFiles[USER_DEF_CONFIG_FILE],id_0,id_1);
	/*if(gBoot_option)
		address += SIZEOF_IDENTIFICATION;
	buffer = (unsigned char *)(INTERNAL_USER_CFG_FILE_ADDRESS + SIZEOF_FILEHEADER + address);
	memcpy(data,buffer,size);*/
	if(gBoot_option)
	{
		address += CfgFiles[FACTORY_CONFIG_FILE].sector_number * AT25DFX_SECTOR_SIZE;
		address += SIZEOF_IDENTIFICATION;
		address += SIZEOF_FILEHEADER;
	}
	else
	{
		address += CfgFiles[USER_DEF_CONFIG_FILE].sector_number * AT25DFX_SECTOR_SIZE;
		address += SIZEOF_FILEHEADER;
	}
	at25dfx_read_bytes(address,size,data);
}


